package com.hs.jhzd.repository;

import java.util.List;
import java.util.Optional;

import com.hs.jhzd.entity.DormArea;
import org.springframework.data.jpa.repository.JpaRepository;
import com.hs.jhzd.entity.Dorm;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import javax.transaction.Transactional;

public interface DormRepository extends JpaRepository<Dorm, String> {



  List<Dorm> findByAreacodeOrderByDormcode(String areacode);

  @Query(value="select QYBH from jc_qyxxb order by QYBH DESC limit  1",nativeQuery=true)
  String findZybh();
  @Query("select new com.hs.jhzd.entity.DormArea(u.id,u.dormcode,u.dormname) from Dorm u where u.dormtype=11")
  List<DormArea> findAllDormArea();
  @Query("select new com.hs.jhzd.entity.DormArea(u.id,u.dormcode,u.dormname) from Dorm u where u.id =:id ")
  Optional<DormArea> findByIdDormArea(@Param("id") String id);
  @Transactional
  @Modifying
  @Query("update Dorm j set j.dormcode=?1,j.dormname=?2  where j.id=?3")
  void updateDormArea( String areacode, String areaname,String id);
  @Transactional
  @Modifying
  @Query("update Dorm j set j.areacode=?1,j.dormcode=?2,j.dormname=?3,j.dormtype=?4 where j.id=?5")
  void updateDorm(String areaname, String dormcode, String dormname, String dormtype, String id);

  List<Dorm> findByDormtypeNot(String i);
}
